package com.lottery.ruok.lottrey.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.fragment.EmojiconsFragment;

import java.util.ArrayList;

/**
 * Created by ASUS on 2017/11/13.
 */

public class EmojiconsAdapter extends BaseAdapter {
    private EmojiconsFragment emojiconsFragment;
    private ArrayList<Integer> datas;
    public EmojiconsAdapter(EmojiconsFragment emojiconsFragment, ArrayList<Integer> datas) {
        this.emojiconsFragment = emojiconsFragment;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(emojiconsFragment.getActivity()).inflate(R.layout.emoji_item, null, false);
            holder.name = convertView.findViewById(R.id.name);
            holder.backspace = convertView.findViewById(R.id.backspace);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if(position == datas.size() - 1){
            holder.name.setVisibility(View.GONE);
            holder.backspace.setVisibility(View.VISIBLE);
        } else {
            holder.name.setText(emojiconsFragment.getEmojiStringByUnicode(datas.get(position)));
            holder.backspace.setVisibility(View.GONE);
        }

        return convertView;

    }


    static class ViewHolder {
        TextView name;
        ImageView backspace;
    }
}